package com.project.service.imp;

import com.project.bean.FacilityBean;
import com.project.dao.IFacilityDao;
import com.project.dao.IRoomDao;
import com.project.service.FacilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FacilityServiecImp implements FacilityService {
    @Autowired
    private IFacilityDao dao;
    @Autowired
    private IRoomDao roomDao;

    @Override
    public List<FacilityBean> findById(Integer id) {
        return dao.findById(id);
    }

    @Override
    public void updateOver(Integer id, Integer roomId) {
        dao.updateStatus(id, "已解决");
        if (dao.findFacilitiesNum(roomId,"未解决")==0){
            roomDao.updateRoomStatus(roomId,"正常");
        }
    }

    @Override
    public void add(FacilityBean facilityBean) {
        dao.add(facilityBean);
        roomDao.updateRoomStatus(facilityBean.getRoomBean().getId(),"损坏");
    }
}
